var romanToInt = function (s) {
  let num, sum = 0
  var map = new Map([
    ['I', 1], ['V', 5], ['X', 10], ['L', 50], ['C', 100], ['D', 500], ['M', 1000]
  ])
  for (var i = 0; i < s.length; i++) {
    num = map.get(s[i])
    if (map.get(s[i]) < map.get(s[i + 1])) {
      num = -num
    }
    sum += num
  }
  return sum
};
let s = 'MCCMCM'
console.log(romanToInt(s));